import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import axios from 'axios'
import qs from 'qs'
import { usersUrl } from '@/utils/url.js'
const state = {
    list: []
}
const mutations = {
    setList(state, data) {
        state.list = data
    }
}
const actions = {
    save({ commit }, obj) {
        return new Promise((resolve, reject) => {
            axios({
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                url: usersUrl,
                method: "post",
                data: qs.stringify(obj)
            }).then(res => {
                resolve()
            })
        })
    },
    get({ commit }, obj) {
        return new Promise((resolve, reject) => {
            axios({
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                url: usersUrl,
                method: "get",
                params: {
                    search: obj.search,
                    id: obj.id,
                    page: obj.curP,
                    pageSize: obj.pageSize,
                    order: obj.order
                }
            }).then(res => {
                commit('setList', res.data.data)
                resolve(res)
            }).catch(e => { reject() })
        })
    }
}
const getters = {
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}
